package com.cswangdao.controller.admin;

import cn.hutool.json.JSONUtil;
import com.cswangdao.annotation.OperationLog;
import com.cswangdao.domain.vo.AdminInfo;
import com.cswangdao.domain.vo.AdminVo;
import com.cswangdao.result.Result;
import com.cswangdao.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RequestMapping("/admin/auth")
@Slf4j
@RestController
public class AdminAuthController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    @OperationLog("后台系统登录")
    public Result<AdminVo> login(@RequestBody Map map, HttpSession session) {
        log.info("后台系统登录：{}", JSONUtil.toJsonStr(map));
        AdminVo adminVo = adminService.login(map, session);
        return Result.success(adminVo);

    }

    @GetMapping("/info")
    public Result<AdminInfo> info(HttpSession session) {
        Integer adminId = (Integer) session.getAttribute("adminId");
        log.info("adminId:{}", adminId);
        AdminInfo adminInfo = adminService.getAdminInfoById(adminId);
        return Result.success(adminInfo);
    }

}
